// personcenter.js
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radioItems: [{
      value: "企业单位",
      index: 1,
      checked: 'true'
    }, {
      value: "个人/非企业",
      index: 2,
    }],
    appColor: app.appColor,
    feeText: "请输入税号",
    


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.code = options.code;
  },
  radioChange: function(e) {
    let index = e.detail.value;
    if(index == 1){
      this.setData({
        inputdisabled: "",
        feeText: "请输入税号"
      })
    }else{
      this.setData({
        inputdisabled: "disabled",
        feeText: "不需要填写税号"
      })
    }
  },
  // 发票开取
  submit: function(e) {
    let val = e.detail.value;
    wx.request({
      url: app.serviceurl + 'Order/ApplyInvoice',
      header: {
        Authorization: "Bearer " + app.accesstoken
      },
      data: {
        orderCode: this.code,
        title: val.title,
        taxNum: val.num,
        email: val.email
      },
      dataType: 'json',
      success: function(res) {
        if (!res.data.result) {
          wx.showModal({
            title: "发票开取失败",
            content: res.data.msg,
            showCancel: false,
            confirmText: "确定",
            success: function(res) {}
          })
          return
        };
        wx.showModal({
          title: "发票开取成功",
          content: "稍后我们会向您的邮箱中发放一份电子发票，请注意查收（如果当天未收到电子发票请联系客服）！",
          showCancel: false,
          confirmText: "确定",
          success: function(res) {}
        })
      },
      fail: function() {
        wx.showModal({
          title: "请求失败",
          content: "通讯故障，请稍后再试",
          showCancel: false,
          confirmText: "确定",
          success: function(res) {}
        })
      },
      complete: function() {}
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.setData({
      IsRegister: app.IsRegister,
      HandsetNumber: app.HandsetNumber
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  bind: function() {
    wx.navigateTo({
      url: '../bindPhone/bindPhone',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    if (res.from === 'menu') {
      return app.OnShare();
    }
  },
  contact: function(e) {
    wx.navigateTo({
      url: '/pages/contact/contact',
    })
  },
  message: function(e) {
    wx.navigateTo({
      url: './message/message',
    })
  },
  indent: function(e) {
    wx.navigateTo({
      url: './indent/indent',
    })
  },
  ticket: function(e) {
    wx.navigateTo({
      url: '/pages/customline/ticket/ticket',
    })
  },
  list: function(e) {
    wx.navigateTo({
      url: '/pages/rent/list/list',
    })
  }
})